/**
 * 
 */
package ma.hamada.controller;

import java.awt.event.ActionEvent;

import javax.swing.JButton;

import ma.hamada.model.PieceModel;
import ma.hamada.model.PiecePosition;
import ma.hamada.swing.JPieceView;
import ma.hamada.view.PieceView;

/**
 * @author M.ABDELOUHAB
 * 
 */
public class PieceController {

	public PieceView pieceView = null;

	private PieceModel model = null;
	
	PuzzleController puzzleController=null;

	public PieceController(PieceModel model) {
		this.model = model;

		pieceView = new JPieceView(this);

		addListenersToModel();
	}
	
	public PieceController(PieceModel model,PuzzleController puzzleController) {
		this.model = model;
		this.puzzleController=puzzleController;

		pieceView = new JPieceView(this);

		addListenersToModel();
	}

	private void addListenersToModel() {
		model.addPiecePositionListener(pieceView);
	}

	public void displayViews() {
		pieceView.display();
	}

	public void closeViews() {
		pieceView.close();
	}

	public void notifyPositionChanged(ActionEvent e) {
		this.puzzleController.notifyPositionChanged(e);
	}

	/**
	 * @return the puzzleController
	 */
	public PuzzleController getPuzzleController() {
		return puzzleController;
	}

	/**
	 * @param puzzleController the puzzleController to set
	 */
	public void setPuzzleController(PuzzleController puzzleController) {
		this.puzzleController = puzzleController;
	}

}
